#coding:utf-8
# -*- coding: utf-8 -*-
#@Time : 2020/12/4 21:03
#@Author: 王鹏-wangpeng99
#@File : Test.py

from datetime import datetime
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from datetime import timedelta
from faker import Faker

zhfaker = Faker(locale='zh-CN')

# 创建engine
engine = create_engine("sqlite:///db/batterydash.db?charset=utf8&check_same_thread=False", echo=True)
# 创建session类型
DBSession = sessionmaker(bind=engine)
# 创建session对象，进行增删改查:
session = DBSession()


for _ in range(100):
    dt=zhfaker.past_datetime(start_date="-30d", tzinfo=None)
    dtstr=dt.strftime("%Y-%m-%d %H:%M:%S")
    volt=zhfaker.pyfloat(left_digits=2, right_digits=3,positive=True)
    current = zhfaker.random_digit()
    battery=zhfaker.random_digit()
    sql="""insert into battery(ts,volt,current,battery) values("{}",{},{},{})""".format(dtstr,volt,current,battery)
    print(sql)
    session.execute(sql)
    session.commit()

